package com.example.demo.Mappers;

import com.example.demo.beans.GetJzjlInfo;
import com.example.demo.beans.GetRecipeListItem3;
import com.example.demo.beans.GetRecipeListtem1;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by Administrator on 2018-05-06.
 */
@Mapper
public interface GetRecipeListMapper {
    @Select("\n" +
            "select  ItemID,ItemName,ItemType,Specs,Unit,Price,Num from Auto_View_cfmx where sfjs='0' and  ryghxh=#{ryghxh} and yzlx=#{yzlx}"
    )
    List<GetRecipeListtem1> selectdetailRecipe(@Param("ryghxh")String ryghxh,@Param("yzlx")String yzlx);
   @Select("select  DeptID,DeptName, DoctName, RecipeID,RecipeName,RecipeType,RecipeAmount,ExecDept ,ExecLocation,RecipeDate,ExecDate,Note,ghxh,yzlx  from Auto_View_cfsq where kfbz='0'and PatientID=#{PatientID} ")
/**   @Results(value = {
           @Result(column = "DeptID",property = "DeptID"),
           @Result(column = "DeptName",property = "DeptName"),
           @Result(column = "DoctName",property = "DoctName"),
           @Result(column = "RecipeID",property = "RecipeID"),
           @Result(column = "RecipeName",property = "RecipeName"),
           @Result(column = "RecipeType",property = "RecipeType"),
           @Result(column = "RecipeAmount",property = "RecipeAmount"),
           @Result(column = "ExecDept",property = "ExecDept"),
           @Result(column = "ExecLocation",property = "ExecLocation"),
           @Result(column = "RecipeDate",property = "RecipeDate"),
           @Result(column = "ExecDate",property = "ExecDate"),
           @Result(column = "Note",property = "Note"),
           @Result(column = "ghxh",property = "ghxh"),
           @Result(column = "yzlx",property = "yzlx"),



   })**/
    List<GetRecipeListItem3>selectRecipe(@Param("PatientID")String PatientID);

/**更新门诊医生检验申请**/
    @Update("update mzys_jysq Set kfbz ='1' , kfry =#{kfry} , kfrq =#{kfrq} Where ryghxh =#{ryghxh} And kfbz ='0' ")
    void  UpdateMzysjysq(@Param("kfry")String kfry,@Param("kfrq")String kfrq,@Param("ryghxh")String ryghxh);
/**g更新门诊医生检查申请**/
    @Update("update mzys_jcsq Set kfbz ='1' , kfry =#{kfry} , kfrq =#{kfrq} Where ryghxh =#{ryghxh} And kfbz ='0' ")
    void  UpdateMzysjcsq(@Param("kfry")String kfry,@Param("kfrq")String kfrq,@Param("ryghxh")String ryghxh);
/**更新门诊医生治疗处置**/
    @Update("update mzys_zlcz Set kfbz ='1' , kfry =#{kfry} , kfrq =#{kfrq} Where ryghxh =#{ryghxh} And kfbz ='0' ")
    void  UpdateMzyszlcz(@Param("kfry")String kfry,@Param("kfrq")String kfrq,@Param("ryghxh")String ryghxh);
   //更新门诊医生门诊手术
    @Update("update mzys_mzss Set kfbz ='1' , kfry =#{kfry} , kfrq =#{kfrq} Where ryghxh =#{ryghxh} And kfbz ='0' ")
    void  UpdateMzysmzss(@Param("kfry")String kfry,@Param("kfrq")String kfrq,@Param("ryghxh")String ryghxh);
    /**更新药房处方表药品**/
    @Update("update yfb_ypcf Set kfbz ='1' , kfry =#{kfry} , kfrq =#{kfrq} Where ghxh =#{ghxh} And kfbz ='0' ")
    void  Updateyfb_ypcf(@Param("kfry")String kfry,@Param("kfrq")String kfrq,@Param("ghxh")String ghxh);

    @Update(" update mzb_brfy set czybm=#{czybm},sfrq=#{sfrq},fphm=#{fphm},sfjs=1,jscs=1,ryjsjlid=#{ryjsjlid},sflx='0',posbz='0' where ryghxh=#{ryghxh}  and yzlx=#{yzlx} and fphm IS NULL and sftf=0 and sfjs=0 and jscs =0 and tfczy IS NULL   ")
    /**更新门诊表病人费用**/
    void Updatemzb_brfy(@Param("czybm")String czybm,@Param("sfrq")String sfrq,@Param("fphm")String fphm, @Param("ryjsjlid")String ryjsjlid, @Param("ryghxh")String ryghxh,@Param("yzlx")String yzlx);
    @Select("select top 1 ID   from AutoRegist  where PatientID=#{PatientID} order by ID desc")
    /**获取医院交易流水号**/
    String gethostraID(@Param("PatientID")String PatientID);

    @Select("SELECT RegID,OperDateTime ,DeptName,DoctName FROM Auto_View_JZJL where CardNo=#{CardNo} or PatientID=#{PatientID} order by  RegID desc ")

    List<GetJzjlInfo> getjzjlinfo(@Param("CardNo") String CardNo,@Param("PatientID") String PatientID);

    @Select("select  DeptID,DeptName, DoctName, RecipeID,RecipeName,RecipeType,RecipeAmount,ExecDept ,ExecLocation,RecipeDate,ExecDate,Note,ghxh,yzlx  from Auto_View_cfsq where kfbz='0'and ghxh=#{ghxh} ")
    //获取处方信息
    List<GetRecipeListItem3>selectRecipe1(@Param("ghxh")String ghxh);

    @Select("select  ItemID,ItemName,ItemType,Specs,Unit,Price,Num from Auto_View_cfmx1 where RecipeID=#{RecipeID} and yzlx=#{yzlx}"
    )
    //获取处方明细信息
    List<GetRecipeListtem1> selectdetailRecipe1(@Param("RecipeID")String ryghxh,@Param("yzlx")String yzlx);
    @Select("select rtrim(AutoTranNo)AutoTranNo from AutoRegist where AutoTranNo=#{AutoTranNo}")
        //获取订单号用来判断是否进入系统，如果已经在系统里面则不写入
    String GetOderId(@Param("AutoTranNo")String AutoTranNo);

    @Select("select top 1 a.ID  from AutoRegist a where a.PatientID=#{PatientID} order by a.ID desc")
        //获取网络交易中的流水号用来更新jsjl的网络交易ID
    String GetAutonetId(@Param("PatientID")String PatientID);
    @Update("update ghb_jsjl set autonetid=#{autonetid} where ghxh=#{ghxh} and brid=#{brid} and autonetid is null and jsjlid=#{jsjlid} ")
        //更新结算记录中网络交易流水号
    void  UpAutonetId(@Param("autonetid")String autonetid,@Param("ghxh")String ghxh,@Param("brid")String brid,@Param("jsjlid")String jsjlid);
    @Select("select  isnull(SUM(fyje),0)zje  from mzb_brfy where ryghxh=#{ryghxh} and fphm IS NULL and sftf=0 and sfjs=0 and jscs =0 and tfczy IS NULL ")
        //获取门诊表未缴费用总额用于判断是否和应缴费用相等
    String getnotPaymony(@Param("ryghxh")String ryghxh);
}
